forked from aniani/vim
patch 8.1.2173: searchit() has too many arguments
Problem: Searchit() has too many arguments. Solution: Move optional arguments to a struct. Add the "wrapped" argument.
This commit is contained in:
@@ -5694,12 +5694,13 @@ search_cmn(typval_T *argvars, pos_T *match_pos, int *flagsp)
|
||||
int dir;
|
||||
int retval = 0; /* default: FAIL */
|
||||
long lnum_stop = 0;
|
||||
proftime_T tm;
|
||||
#ifdef FEAT_RELTIME
|
||||
proftime_T tm;
|
||||
long time_limit = 0;
|
||||
#endif
|
||||
int options = SEARCH_KEEP;
|
||||
int subpatnum;
|
||||
searchit_arg_T sia;
|
||||
|
||||
pat = tv_get_string(&argvars[0]);
|
||||
dir = get_search_arg(&argvars[1], flagsp); /* may set p_ws */
|
||||
@@ -5748,8 +5749,13 @@ search_cmn(typval_T *argvars, pos_T *match_pos, int *flagsp)
|
||||
}
|
||||
|
||||
pos = save_cursor = curwin->w_cursor;
|
||||
vim_memset(&sia, 0, sizeof(sia));
|
||||
sia.sa_stop_lnum = (linenr_T)lnum_stop;
|
||||
#ifdef FEAT_RELTIME
|
||||
sia.sa_tm = &tm;
|
||||
#endif
|
||||
subpatnum = searchit(curwin, curbuf, &pos, NULL, dir, pat, 1L,
|
||||
options, RE_SEARCH, (linenr_T)lnum_stop, &tm, NULL);
|
||||
options, RE_SEARCH, &sia);
|
||||
if (subpatnum != FAIL)
|
||||
{
|
||||
if (flags & SP_SUBPAT)
|
||||
@@ -6147,7 +6153,9 @@ do_searchpair(
|
||||
int use_skip = FALSE;
|
||||
int err;
|
||||
int options = SEARCH_KEEP;
|
||||
#ifdef FEAT_RELTIME
|
||||
proftime_T tm;
|
||||
#endif
|
||||
|
||||
/* Make 'cpoptions' empty, the 'l' flag should not be used here. */
|
||||
save_cpo = p_cpo;
|
||||
@@ -6188,8 +6196,15 @@ do_searchpair(
|
||||
pat = pat3;
|
||||
for (;;)
|
||||
{
|
||||
searchit_arg_T sia;
|
||||
|
||||
vim_memset(&sia, 0, sizeof(sia));
|
||||
sia.sa_stop_lnum = lnum_stop;
|
||||
#ifdef FEAT_RELTIME
|
||||
sia.sa_tm = &tm;
|
||||
#endif
|
||||
n = searchit(curwin, curbuf, &pos, NULL, dir, pat, 1L,
|
||||
options, RE_SEARCH, lnum_stop, &tm, NULL);
|
||||
options, RE_SEARCH, &sia);
|
||||
if (n == FAIL || (firstpos.lnum != 0 && EQUAL_POS(pos, firstpos)))
|
||||
/* didn't find it or found the first match again: FAIL */
|
||||
break;
|
||||
|
||||
@@ -3600,7 +3600,7 @@ get_address(
|
||||
curwin->w_cursor.col = 0;
|
||||
searchcmdlen = 0;
|
||||
flags = silent ? 0 : SEARCH_HIS | SEARCH_MSG;
|
||||
if (!do_search(NULL, c, cmd, 1L, flags, NULL, NULL))
|
||||
if (!do_search(NULL, c, cmd, 1L, flags, NULL))
|
||||
{
|
||||
curwin->w_cursor = pos;
|
||||
cmd = NULL;
|
||||
@@ -3654,8 +3654,7 @@ get_address(
|
||||
pos.coladd = 0;
|
||||
if (searchit(curwin, curbuf, &pos, NULL,
|
||||
*cmd == '?' ? BACKWARD : FORWARD,
|
||||
(char_u *)"", 1L, SEARCH_MSG,
|
||||
i, (linenr_T)0, NULL, NULL) != FAIL)
|
||||
(char_u *)"", 1L, SEARCH_MSG, i, NULL) != FAIL)
|
||||
lnum = pos.lnum;
|
||||
else
|
||||
{
|
||||
|
||||
@@ -373,6 +373,7 @@ may_do_incsearch_highlighting(
|
||||
pos_T end_pos;
|
||||
#ifdef FEAT_RELTIME
|
||||
proftime_T tm;
|
||||
searchit_arg_T sia;
|
||||
#endif
|
||||
int next_char;
|
||||
int use_last_pat;
|
||||
@@ -445,12 +446,16 @@ may_do_incsearch_highlighting(
|
||||
if (search_first_line != 0)
|
||||
search_flags += SEARCH_START;
|
||||
ccline.cmdbuff[skiplen + patlen] = NUL;
|
||||
#ifdef FEAT_RELTIME
|
||||
vim_memset(&sia, 0, sizeof(sia));
|
||||
sia.sa_tm = &tm;
|
||||
#endif
|
||||
found = do_search(NULL, firstc == ':' ? '/' : firstc,
|
||||
ccline.cmdbuff + skiplen, count, search_flags,
|
||||
#ifdef FEAT_RELTIME
|
||||
&tm, NULL
|
||||
&sia
|
||||
#else
|
||||
NULL, NULL
|
||||
NULL
|
||||
#endif
|
||||
);
|
||||
ccline.cmdbuff[skiplen + patlen] = next_char;
|
||||
@@ -597,8 +602,7 @@ may_adjust_incsearch_highlighting(
|
||||
pat[patlen] = NUL;
|
||||
i = searchit(curwin, curbuf, &t, NULL,
|
||||
c == Ctrl_G ? FORWARD : BACKWARD,
|
||||
pat, count, search_flags,
|
||||
RE_SEARCH, 0, NULL, NULL);
|
||||
pat, count, search_flags, RE_SEARCH, NULL);
|
||||
--emsg_off;
|
||||
pat[patlen] = save;
|
||||
if (i)
|
||||
|
||||
@@ -5383,7 +5383,7 @@ gui_do_findrepl(
|
||||
i = msg_scroll;
|
||||
if (down)
|
||||
{
|
||||
(void)do_search(NULL, '/', ga.ga_data, 1L, searchflags, NULL, NULL);
|
||||
(void)do_search(NULL, '/', ga.ga_data, 1L, searchflags, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -5391,7 +5391,7 @@ gui_do_findrepl(
|
||||
* direction */
|
||||
p = vim_strsave_escaped(ga.ga_data, (char_u *)"?");
|
||||
if (p != NULL)
|
||||
(void)do_search(NULL, '?', p, 1L, searchflags, NULL, NULL);
|
||||
(void)do_search(NULL, '?', p, 1L, searchflags, NULL);
|
||||
vim_free(p);
|
||||
}
|
||||
|
||||
|
||||
@@ -2881,7 +2881,7 @@ ins_compl_get_exp(pos_T *ini)
|
||||
found_new_match = searchit(NULL, ins_buf, pos, NULL,
|
||||
compl_direction,
|
||||
compl_pattern, 1L, SEARCH_KEEP + SEARCH_NFMSG,
|
||||
RE_LAST, (linenr_T)0, NULL, NULL);
|
||||
RE_LAST, NULL);
|
||||
--msg_silent;
|
||||
if (!compl_started || set_match_pos)
|
||||
{
|
||||
|
||||
26
src/normal.c
26
src/normal.c
@@ -65,7 +65,7 @@ static void nv_end(cmdarg_T *cap);
|
||||
static void nv_dollar(cmdarg_T *cap);
|
||||
static void nv_search(cmdarg_T *cap);
|
||||
static void nv_next(cmdarg_T *cap);
|
||||
static int normal_search(cmdarg_T *cap, int dir, char_u *pat, int opt);
|
||||
static int normal_search(cmdarg_T *cap, int dir, char_u *pat, int opt, int *wrapped);
|
||||
static void nv_csearch(cmdarg_T *cap);
|
||||
static void nv_brackets(cmdarg_T *cap);
|
||||
static void nv_percent(cmdarg_T *cap);
|
||||
@@ -2346,7 +2346,7 @@ find_decl(
|
||||
for (;;)
|
||||
{
|
||||
t = searchit(curwin, curbuf, &curwin->w_cursor, NULL, FORWARD,
|
||||
pat, 1L, searchflags, RE_LAST, (linenr_T)0, NULL, NULL);
|
||||
pat, 1L, searchflags, RE_LAST, NULL);
|
||||
if (curwin->w_cursor.lnum >= old_pos.lnum)
|
||||
t = FAIL; /* match after start is failure too */
|
||||
|
||||
@@ -3730,7 +3730,7 @@ nv_ident(cmdarg_T *cap)
|
||||
init_history();
|
||||
add_to_history(HIST_SEARCH, buf, TRUE, NUL);
|
||||
|
||||
(void)normal_search(cap, cmdchar == '*' ? '/' : '?', buf, 0);
|
||||
(void)normal_search(cap, cmdchar == '*' ? '/' : '?', buf, 0, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -4257,7 +4257,7 @@ nv_search(cmdarg_T *cap)
|
||||
|
||||
(void)normal_search(cap, cap->cmdchar, cap->searchbuf,
|
||||
(cap->arg || !EQUAL_POS(save_cursor, curwin->w_cursor))
|
||||
? 0 : SEARCH_MARK);
|
||||
? 0 : SEARCH_MARK, NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -4267,16 +4267,17 @@ nv_search(cmdarg_T *cap)
|
||||
static void
|
||||
nv_next(cmdarg_T *cap)
|
||||
{
|
||||
pos_T old = curwin->w_cursor;
|
||||
int i = normal_search(cap, 0, NULL, SEARCH_MARK | cap->arg);
|
||||
pos_T old = curwin->w_cursor;
|
||||
int wrapped = FALSE;
|
||||
int i = normal_search(cap, 0, NULL, SEARCH_MARK | cap->arg, &wrapped);
|
||||
|
||||
if (i == 1 && EQUAL_POS(old, curwin->w_cursor))
|
||||
if (i == 1 && !wrapped && EQUAL_POS(old, curwin->w_cursor))
|
||||
{
|
||||
/* Avoid getting stuck on the current cursor position, which can
|
||||
* happen when an offset is given and the cursor is on the last char
|
||||
* in the buffer: Repeat with count + 1. */
|
||||
cap->count1 += 1;
|
||||
(void)normal_search(cap, 0, NULL, SEARCH_MARK | cap->arg);
|
||||
(void)normal_search(cap, 0, NULL, SEARCH_MARK | cap->arg, NULL);
|
||||
cap->count1 -= 1;
|
||||
}
|
||||
}
|
||||
@@ -4291,17 +4292,22 @@ normal_search(
|
||||
cmdarg_T *cap,
|
||||
int dir,
|
||||
char_u *pat,
|
||||
int opt) /* extra flags for do_search() */
|
||||
int opt, // extra flags for do_search()
|
||||
int *wrapped)
|
||||
{
|
||||
int i;
|
||||
searchit_arg_T sia;
|
||||
|
||||
cap->oap->motion_type = MCHAR;
|
||||
cap->oap->inclusive = FALSE;
|
||||
cap->oap->use_reg_one = TRUE;
|
||||
curwin->w_set_curswant = TRUE;
|
||||
|
||||
vim_memset(&sia, 0, sizeof(sia));
|
||||
i = do_search(cap->oap, dir, pat, cap->count1,
|
||||
opt | SEARCH_OPT | SEARCH_ECHO | SEARCH_MSG, NULL, NULL);
|
||||
opt | SEARCH_OPT | SEARCH_ECHO | SEARCH_MSG, &sia);
|
||||
if (wrapped != NULL)
|
||||
*wrapped = sia.sa_wrapped;
|
||||
if (i == 0)
|
||||
clearop(cap->oap);
|
||||
else
|
||||
|
||||
@@ -22,9 +22,9 @@ char_u *last_search_pat(void);
|
||||
void reset_search_dir(void);
|
||||
void set_last_search_pat(char_u *s, int idx, int magic, int setlast);
|
||||
void last_pat_prog(regmmatch_T *regmatch);
|
||||
int searchit(win_T *win, buf_T *buf, pos_T *pos, pos_T *end_pos, int dir, char_u *pat, long count, int options, int pat_use, linenr_T stop_lnum, proftime_T *tm, int *timed_out);
|
||||
int searchit(win_T *win, buf_T *buf, pos_T *pos, pos_T *end_pos, int dir, char_u *pat, long count, int options, int pat_use, searchit_arg_T *extra_arg);
|
||||
void set_search_direction(int cdir);
|
||||
int do_search(oparg_T *oap, int dirc, char_u *pat, long count, int options, proftime_T *tm, int *timed_out);
|
||||
int do_search(oparg_T *oap, int dirc, char_u *pat, long count, int options, searchit_arg_T *sia);
|
||||
int search_for_exact_line(buf_T *buf, pos_T *pos, int dir, char_u *pat);
|
||||
int searchc(cmdarg_T *cap, int t_cmd);
|
||||
pos_T *findmatch(oparg_T *oap, int initc);
|
||||
@@ -46,6 +46,6 @@ int current_quote(oparg_T *oap, long count, int include, int quotechar);
|
||||
int current_search(long count, int forward);
|
||||
int linewhite(linenr_T lnum);
|
||||
void find_pattern_in_path(char_u *ptr, int dir, int len, int whole, int skip_comments, int type, long count, int action, linenr_T start_lnum, linenr_T end_lnum);
|
||||
struct spat *get_spat(int idx);
|
||||
spat_T *get_spat(int idx);
|
||||
int get_spat_last_idx(void);
|
||||
/* vim: set ft=c : */
|
||||
|
||||
@@ -3207,8 +3207,7 @@ qf_jump_goto_line(
|
||||
// Move the cursor to the first line in the buffer
|
||||
save_cursor = curwin->w_cursor;
|
||||
curwin->w_cursor.lnum = 0;
|
||||
if (!do_search(NULL, '/', qf_pattern, (long)1,
|
||||
SEARCH_KEEP, NULL, NULL))
|
||||
if (!do_search(NULL, '/', qf_pattern, (long)1, SEARCH_KEEP, NULL))
|
||||
curwin->w_cursor = save_cursor;
|
||||
}
|
||||
}
|
||||
|
||||
40
src/search.c
40
src/search.c
@@ -595,8 +595,8 @@ last_pat_prog(regmmatch_T *regmatch)
|
||||
*/
|
||||
int
|
||||
searchit(
|
||||
win_T *win, /* window to search in; can be NULL for a
|
||||
buffer without a window! */
|
||||
win_T *win, // window to search in; can be NULL for a
|
||||
// buffer without a window!
|
||||
buf_T *buf,
|
||||
pos_T *pos,
|
||||
pos_T *end_pos, // set to end of the match, unless NULL
|
||||
@@ -604,10 +604,8 @@ searchit(
|
||||
char_u *pat,
|
||||
long count,
|
||||
int options,
|
||||
int pat_use, /* which pattern to use when "pat" is empty */
|
||||
linenr_T stop_lnum, /* stop after this line number when != 0 */
|
||||
proftime_T *tm UNUSED, /* timeout limit or NULL */
|
||||
int *timed_out UNUSED) /* set when timed out or NULL */
|
||||
int pat_use, // which pattern to use when "pat" is empty
|
||||
searchit_arg_T *extra_arg) // optional extra arguments, can be NULL
|
||||
{
|
||||
int found;
|
||||
linenr_T lnum; /* no init to shut up Apollo cc */
|
||||
@@ -630,6 +628,20 @@ searchit(
|
||||
#ifdef FEAT_SEARCH_EXTRA
|
||||
int break_loop = FALSE;
|
||||
#endif
|
||||
linenr_T stop_lnum = 0; // stop after this line number when != 0
|
||||
#ifdef FEAT_RELTIME
|
||||
proftime_T *tm = NULL; // timeout limit or NULL
|
||||
int *timed_out = NULL; // set when timed out or NULL
|
||||
#endif
|
||||
|
||||
if (extra_arg != NULL)
|
||||
{
|
||||
stop_lnum = extra_arg->sa_stop_lnum;
|
||||
#ifdef FEAT_RELTIME
|
||||
tm = extra_arg->sa_tm;
|
||||
timed_out = &extra_arg->sa_timed_out;
|
||||
#endif
|
||||
}
|
||||
|
||||
if (search_regcomp(pat, RE_SEARCH, pat_use,
|
||||
(options & (SEARCH_HIS + SEARCH_KEEP)), ®match) == FAIL)
|
||||
@@ -1067,6 +1079,8 @@ searchit(
|
||||
if (!shortmess(SHM_SEARCH) && (options & SEARCH_MSG))
|
||||
give_warning((char_u *)_(dir == BACKWARD
|
||||
? top_bot_msg : bot_top_msg), TRUE);
|
||||
if (extra_arg != NULL)
|
||||
extra_arg->sa_wrapped = TRUE;
|
||||
}
|
||||
if (got_int || called_emsg
|
||||
#ifdef FEAT_RELTIME
|
||||
@@ -1178,8 +1192,7 @@ do_search(
|
||||
char_u *pat,
|
||||
long count,
|
||||
int options,
|
||||
proftime_T *tm, /* timeout limit or NULL */
|
||||
int *timed_out) /* flag set on timeout or NULL */
|
||||
searchit_arg_T *sia) // optional arguments or NULL
|
||||
{
|
||||
pos_T pos; /* position of the last match */
|
||||
char_u *searchstr;
|
||||
@@ -1269,7 +1282,7 @@ do_search(
|
||||
*/
|
||||
for (;;)
|
||||
{
|
||||
int show_top_bot_msg = FALSE;
|
||||
int show_top_bot_msg = FALSE;
|
||||
|
||||
searchstr = pat;
|
||||
dircp = NULL;
|
||||
@@ -1511,7 +1524,7 @@ do_search(
|
||||
(SEARCH_KEEP + SEARCH_PEEK + SEARCH_HIS
|
||||
+ SEARCH_MSG + SEARCH_START
|
||||
+ ((pat != NULL && *pat == ';') ? 0 : SEARCH_NOOF))),
|
||||
RE_LAST, (linenr_T)0, tm, timed_out);
|
||||
RE_LAST, sia);
|
||||
|
||||
if (dircp != NULL)
|
||||
*dircp = dirc; // restore second '/' or '?' for normal_cmd()
|
||||
@@ -4741,7 +4754,7 @@ current_search(
|
||||
result = searchit(curwin, curbuf, &pos, &end_pos,
|
||||
(dir ? FORWARD : BACKWARD),
|
||||
spats[last_idx].pat, (long) (i ? count : 1),
|
||||
SEARCH_KEEP | flags, RE_SEARCH, 0, NULL, NULL);
|
||||
SEARCH_KEEP | flags, RE_SEARCH, NULL);
|
||||
|
||||
/* First search may fail, but then start searching from the
|
||||
* beginning of the file (cursor might be on the search match)
|
||||
@@ -4854,7 +4867,7 @@ is_one_char(char_u *pattern, int move, pos_T *cur, int direction)
|
||||
}
|
||||
|
||||
if (searchit(curwin, curbuf, &pos, NULL, direction, pattern, 1,
|
||||
SEARCH_KEEP + flag, RE_SEARCH, 0, NULL, NULL) != FAIL)
|
||||
SEARCH_KEEP + flag, RE_SEARCH, NULL) != FAIL)
|
||||
{
|
||||
/* Zero-width pattern should match somewhere, then we can check if
|
||||
* start and end are in the same position. */
|
||||
@@ -4954,8 +4967,7 @@ search_stat(
|
||||
profile_setlimit(20L, &start);
|
||||
#endif
|
||||
while (!got_int && searchit(curwin, curbuf, &lastpos, NULL,
|
||||
FORWARD, NULL, 1, SEARCH_KEEP, RE_LAST,
|
||||
(linenr_T)0, NULL, NULL) != FAIL)
|
||||
FORWARD, NULL, 1, SEARCH_KEEP, RE_LAST, NULL) != FAIL)
|
||||
{
|
||||
#ifdef FEAT_RELTIME
|
||||
// Stop after passing the time limit.
|
||||
|
||||
@@ -2861,7 +2861,7 @@ ex_spellrepall(exarg_T *eap UNUSED)
|
||||
curwin->w_cursor.lnum = 0;
|
||||
while (!got_int)
|
||||
{
|
||||
if (do_search(NULL, '/', frompat, 1L, SEARCH_KEEP, NULL, NULL) == 0
|
||||
if (do_search(NULL, '/', frompat, 1L, SEARCH_KEEP, NULL) == 0
|
||||
|| u_save_cursor() == FAIL)
|
||||
break;
|
||||
|
||||
|
||||
@@ -3871,6 +3871,19 @@ typedef struct spat
|
||||
soffset_T off;
|
||||
} spat_T;
|
||||
|
||||
/*
|
||||
* Optional extra arguments for searchit().
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
linenr_T sa_stop_lnum; // stop after this line number when != 0
|
||||
#ifdef FEAT_RELTIME
|
||||
proftime_T *sa_tm; // timeout limit or NULL
|
||||
int sa_timed_out; // set when timed out
|
||||
#endif
|
||||
int sa_wrapped; // search wrapped around
|
||||
} searchit_arg_T;
|
||||
|
||||
#define WRITEBUFSIZE 8192 // size of normal write buffer
|
||||
|
||||
#define FIO_LATIN1 0x01 // convert Latin1
|
||||
|
||||
@@ -3542,7 +3542,7 @@ jumpto_tag(
|
||||
save_lnum = curwin->w_cursor.lnum;
|
||||
curwin->w_cursor.lnum = 0; /* start search before first line */
|
||||
if (do_search(NULL, pbuf[0], pbuf + 1, (long)1,
|
||||
search_options, NULL, NULL))
|
||||
search_options, NULL))
|
||||
retval = OK;
|
||||
else
|
||||
{
|
||||
@@ -3554,7 +3554,7 @@ jumpto_tag(
|
||||
*/
|
||||
p_ic = TRUE;
|
||||
if (!do_search(NULL, pbuf[0], pbuf + 1, (long)1,
|
||||
search_options, NULL, NULL))
|
||||
search_options, NULL))
|
||||
{
|
||||
/*
|
||||
* Failed to find pattern, take a guess: "^func ("
|
||||
@@ -3565,13 +3565,13 @@ jumpto_tag(
|
||||
*tagp.tagname_end = NUL;
|
||||
sprintf((char *)pbuf, "^%s\\s\\*(", tagp.tagname);
|
||||
if (!do_search(NULL, '/', pbuf, (long)1,
|
||||
search_options, NULL, NULL))
|
||||
search_options, NULL))
|
||||
{
|
||||
/* Guess again: "^char * \<func (" */
|
||||
sprintf((char *)pbuf, "^\\[#a-zA-Z_]\\.\\*\\<%s\\s\\*(",
|
||||
tagp.tagname);
|
||||
if (!do_search(NULL, '/', pbuf, (long)1,
|
||||
search_options, NULL, NULL))
|
||||
search_options, NULL))
|
||||
found = 0;
|
||||
}
|
||||
*tagp.tagname_end = cc;
|
||||
|
||||
@@ -741,6 +741,8 @@ static char *(features[]) =
|
||||
|
||||
static int included_patches[] =
|
||||
{ /* Add new patch number below this line */
|
||||
/**/
|
||||
2173,
|
||||
/**/
|
||||
2172,
|
||||
/**/
|
||||
|
||||
Reference in New Issue
Block a user