comparison src/search.c @ 18358:34d5cd432cac v8.1.2173

patch 8.1.2173: searchit() has too many arguments Commit: https://github.com/vim/vim/commit/92ea26b925a0835badb0af2d5887238a4198cabb Author: Bram Moolenaar <Bram@vim.org> Date: Fri Oct 18 20:53:34 2019 +0200 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.
author Bram Moolenaar <Bram@vim.org>
date Fri, 18 Oct 2019 21:00:04 +0200
parents a5de1d88590d
children 7b4d9e1377ee
comparison
equal deleted inserted replaced
18357:ffe2ff94a3e0 18358:34d5cd432cac
593 * When FEAT_EVAL is defined, returns the index of the first matching 593 * When FEAT_EVAL is defined, returns the index of the first matching
594 * subpattern plus one; one if there was none. 594 * subpattern plus one; one if there was none.
595 */ 595 */
596 int 596 int
597 searchit( 597 searchit(
598 win_T *win, /* window to search in; can be NULL for a 598 win_T *win, // window to search in; can be NULL for a
599 buffer without a window! */ 599 // buffer without a window!
600 buf_T *buf, 600 buf_T *buf,
601 pos_T *pos, 601 pos_T *pos,
602 pos_T *end_pos, // set to end of the match, unless NULL 602 pos_T *end_pos, // set to end of the match, unless NULL
603 int dir, 603 int dir,
604 char_u *pat, 604 char_u *pat,
605 long count, 605 long count,
606 int options, 606 int options,
607 int pat_use, /* which pattern to use when "pat" is empty */ 607 int pat_use, // which pattern to use when "pat" is empty
608 linenr_T stop_lnum, /* stop after this line number when != 0 */ 608 searchit_arg_T *extra_arg) // optional extra arguments, can be NULL
609 proftime_T *tm UNUSED, /* timeout limit or NULL */
610 int *timed_out UNUSED) /* set when timed out or NULL */
611 { 609 {
612 int found; 610 int found;
613 linenr_T lnum; /* no init to shut up Apollo cc */ 611 linenr_T lnum; /* no init to shut up Apollo cc */
614 colnr_T col; 612 colnr_T col;
615 regmmatch_T regmatch; 613 regmmatch_T regmatch;
628 int first_match = TRUE; 626 int first_match = TRUE;
629 int save_called_emsg = called_emsg; 627 int save_called_emsg = called_emsg;
630 #ifdef FEAT_SEARCH_EXTRA 628 #ifdef FEAT_SEARCH_EXTRA
631 int break_loop = FALSE; 629 int break_loop = FALSE;
632 #endif 630 #endif
631 linenr_T stop_lnum = 0; // stop after this line number when != 0
632 #ifdef FEAT_RELTIME
633 proftime_T *tm = NULL; // timeout limit or NULL
634 int *timed_out = NULL; // set when timed out or NULL
635 #endif
636
637 if (extra_arg != NULL)
638 {
639 stop_lnum = extra_arg->sa_stop_lnum;
640 #ifdef FEAT_RELTIME
641 tm = extra_arg->sa_tm;
642 timed_out = &extra_arg->sa_timed_out;
643 #endif
644 }
633 645
634 if (search_regcomp(pat, RE_SEARCH, pat_use, 646 if (search_regcomp(pat, RE_SEARCH, pat_use,
635 (options & (SEARCH_HIS + SEARCH_KEEP)), &regmatch) == FAIL) 647 (options & (SEARCH_HIS + SEARCH_KEEP)), &regmatch) == FAIL)
636 { 648 {
637 if ((options & SEARCH_MSG) && !rc_did_emsg) 649 if ((options & SEARCH_MSG) && !rc_did_emsg)
1065 else 1077 else
1066 lnum = 1; 1078 lnum = 1;
1067 if (!shortmess(SHM_SEARCH) && (options & SEARCH_MSG)) 1079 if (!shortmess(SHM_SEARCH) && (options & SEARCH_MSG))
1068 give_warning((char_u *)_(dir == BACKWARD 1080 give_warning((char_u *)_(dir == BACKWARD
1069 ? top_bot_msg : bot_top_msg), TRUE); 1081 ? top_bot_msg : bot_top_msg), TRUE);
1082 if (extra_arg != NULL)
1083 extra_arg->sa_wrapped = TRUE;
1070 } 1084 }
1071 if (got_int || called_emsg 1085 if (got_int || called_emsg
1072 #ifdef FEAT_RELTIME 1086 #ifdef FEAT_RELTIME
1073 || (timed_out != NULL && *timed_out) 1087 || (timed_out != NULL && *timed_out)
1074 #endif 1088 #endif
1176 oparg_T *oap, /* can be NULL */ 1190 oparg_T *oap, /* can be NULL */
1177 int dirc, /* '/' or '?' */ 1191 int dirc, /* '/' or '?' */
1178 char_u *pat, 1192 char_u *pat,
1179 long count, 1193 long count,
1180 int options, 1194 int options,
1181 proftime_T *tm, /* timeout limit or NULL */ 1195 searchit_arg_T *sia) // optional arguments or NULL
1182 int *timed_out) /* flag set on timeout or NULL */
1183 { 1196 {
1184 pos_T pos; /* position of the last match */ 1197 pos_T pos; /* position of the last match */
1185 char_u *searchstr; 1198 char_u *searchstr;
1186 soffset_T old_off; 1199 soffset_T old_off;
1187 int retval; /* Return value */ 1200 int retval; /* Return value */
1267 /* 1280 /*
1268 * Repeat the search when pattern followed by ';', e.g. "/foo/;?bar". 1281 * Repeat the search when pattern followed by ';', e.g. "/foo/;?bar".
1269 */ 1282 */
1270 for (;;) 1283 for (;;)
1271 { 1284 {
1272 int show_top_bot_msg = FALSE; 1285 int show_top_bot_msg = FALSE;
1273 1286
1274 searchstr = pat; 1287 searchstr = pat;
1275 dircp = NULL; 1288 dircp = NULL;
1276 /* use previous pattern */ 1289 /* use previous pattern */
1277 if (pat == NULL || *pat == NUL || *pat == dirc) 1290 if (pat == NULL || *pat == NUL || *pat == dirc)
1509 dirc == '/' ? FORWARD : BACKWARD, 1522 dirc == '/' ? FORWARD : BACKWARD,
1510 searchstr, count, spats[0].off.end + (options & 1523 searchstr, count, spats[0].off.end + (options &
1511 (SEARCH_KEEP + SEARCH_PEEK + SEARCH_HIS 1524 (SEARCH_KEEP + SEARCH_PEEK + SEARCH_HIS
1512 + SEARCH_MSG + SEARCH_START 1525 + SEARCH_MSG + SEARCH_START
1513 + ((pat != NULL && *pat == ';') ? 0 : SEARCH_NOOF))), 1526 + ((pat != NULL && *pat == ';') ? 0 : SEARCH_NOOF))),
1514 RE_LAST, (linenr_T)0, tm, timed_out); 1527 RE_LAST, sia);
1515 1528
1516 if (dircp != NULL) 1529 if (dircp != NULL)
1517 *dircp = dirc; // restore second '/' or '?' for normal_cmd() 1530 *dircp = dirc; // restore second '/' or '?' for normal_cmd()
1518 1531
1519 if (!shortmess(SHM_SEARCH) 1532 if (!shortmess(SHM_SEARCH)
4739 end_pos = pos; 4752 end_pos = pos;
4740 4753
4741 result = searchit(curwin, curbuf, &pos, &end_pos, 4754 result = searchit(curwin, curbuf, &pos, &end_pos,
4742 (dir ? FORWARD : BACKWARD), 4755 (dir ? FORWARD : BACKWARD),
4743 spats[last_idx].pat, (long) (i ? count : 1), 4756 spats[last_idx].pat, (long) (i ? count : 1),
4744 SEARCH_KEEP | flags, RE_SEARCH, 0, NULL, NULL); 4757 SEARCH_KEEP | flags, RE_SEARCH, NULL);
4745 4758
4746 /* First search may fail, but then start searching from the 4759 /* First search may fail, but then start searching from the
4747 * beginning of the file (cursor might be on the search match) 4760 * beginning of the file (cursor might be on the search match)
4748 * except when Visual mode is active, so that extending the visual 4761 * except when Visual mode is active, so that extending the visual
4749 * selection works. */ 4762 * selection works. */
4852 /* accept a match at the cursor position */ 4865 /* accept a match at the cursor position */
4853 flag = SEARCH_START; 4866 flag = SEARCH_START;
4854 } 4867 }
4855 4868
4856 if (searchit(curwin, curbuf, &pos, NULL, direction, pattern, 1, 4869 if (searchit(curwin, curbuf, &pos, NULL, direction, pattern, 1,
4857 SEARCH_KEEP + flag, RE_SEARCH, 0, NULL, NULL) != FAIL) 4870 SEARCH_KEEP + flag, RE_SEARCH, NULL) != FAIL)
4858 { 4871 {
4859 /* Zero-width pattern should match somewhere, then we can check if 4872 /* Zero-width pattern should match somewhere, then we can check if
4860 * start and end are in the same position. */ 4873 * start and end are in the same position. */
4861 called_emsg = FALSE; 4874 called_emsg = FALSE;
4862 do 4875 do
4952 p_ws = FALSE; 4965 p_ws = FALSE;
4953 #ifdef FEAT_RELTIME 4966 #ifdef FEAT_RELTIME
4954 profile_setlimit(20L, &start); 4967 profile_setlimit(20L, &start);
4955 #endif 4968 #endif
4956 while (!got_int && searchit(curwin, curbuf, &lastpos, NULL, 4969 while (!got_int && searchit(curwin, curbuf, &lastpos, NULL,
4957 FORWARD, NULL, 1, SEARCH_KEEP, RE_LAST, 4970 FORWARD, NULL, 1, SEARCH_KEEP, RE_LAST, NULL) != FAIL)
4958 (linenr_T)0, NULL, NULL) != FAIL)
4959 { 4971 {
4960 #ifdef FEAT_RELTIME 4972 #ifdef FEAT_RELTIME
4961 // Stop after passing the time limit. 4973 // Stop after passing the time limit.
4962 if (profile_passed_limit(&start)) 4974 if (profile_passed_limit(&start))
4963 { 4975 {