summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2008-01-06 19:07:36 +0000
committerBram Moolenaar <Bram@vim.org>2008-01-06 19:07:36 +0000
commit76929293e03d4595c95171fc82be05a64673d42e (patch)
treee13452e87e1ca9773bf648f3a8438eb716ac2f82 /src
parent6203ff97b715e0112f90587f9ce576ef0e7798bc (diff)
updated for version 7.1-211v7.1.211
Diffstat (limited to 'src')
-rw-r--r--src/edit.c2
-rw-r--r--src/eval.c55
-rw-r--r--src/ex_cmds2.c66
-rw-r--r--src/ex_docmd.c2
-rw-r--r--src/normal.c2
-rw-r--r--src/proto/eval.pro2
-rw-r--r--src/proto/ex_cmds2.pro2
-rw-r--r--src/proto/search.pro2
-rw-r--r--src/search.c15
-rw-r--r--src/version.c2
10 files changed, 123 insertions, 27 deletions
diff --git a/src/edit.c b/src/edit.c
index 2663e6e98b..138340767d 100644
--- a/src/edit.c
+++ b/src/edit.c
@@ -4062,7 +4062,7 @@ ins_compl_get_exp(ini)
found_new_match = searchit(NULL, ins_buf, pos,
compl_direction,
compl_pattern, 1L, SEARCH_KEEP + SEARCH_NFMSG,
- RE_LAST, (linenr_T)0);
+ RE_LAST, (linenr_T)0, NULL);
--msg_silent;
if (!compl_started)
{
diff --git a/src/eval.c b/src/eval.c
index c03da196c3..4afcb189cb 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -7213,11 +7213,11 @@ static struct fst
{"repeat", 2, 2, f_repeat},
{"resolve", 1, 1, f_resolve},
{"reverse", 1, 1, f_reverse},
- {"search", 1, 3, f_search},
+ {"search", 1, 4, f_search},
{"searchdecl", 1, 3, f_searchdecl},
- {"searchpair", 3, 6, f_searchpair},
- {"searchpairpos", 3, 6, f_searchpairpos},
- {"searchpos", 1, 3, f_searchpos},
+ {"searchpair", 3, 7, f_searchpair},
+ {"searchpairpos", 3, 7, f_searchpairpos},
+ {"searchpos", 1, 4, f_searchpos},
{"server2client", 2, 2, f_server2client},
{"serverlist", 0, 0, f_serverlist},
{"setbufvar", 3, 3, f_setbufvar},
@@ -14020,6 +14020,10 @@ search_cmn(argvars, match_pos, flagsp)
int dir;
int retval = 0; /* default: FAIL */
long lnum_stop = 0;
+ proftime_T tm;
+#ifdef FEAT_RELTIME
+ long time_limit = 0;
+#endif
int options = SEARCH_KEEP;
int subpatnum;
@@ -14033,15 +14037,27 @@ search_cmn(argvars, match_pos, flagsp)
if (flags & SP_END)
options |= SEARCH_END;
- /* Optional extra argument: line number to stop searching. */
- if (argvars[1].v_type != VAR_UNKNOWN
- && argvars[2].v_type != VAR_UNKNOWN)
+ /* Optional arguments: line number to stop searching and timeout. */
+ if (argvars[1].v_type != VAR_UNKNOWN && argvars[2].v_type != VAR_UNKNOWN)
{
lnum_stop = get_tv_number_chk(&argvars[2], NULL);
if (lnum_stop < 0)
goto theend;
+#ifdef FEAT_RELTIME
+ if (argvars[3].v_type != VAR_UNKNOWN)
+ {
+ time_limit = get_tv_number_chk(&argvars[3], NULL);
+ if (time_limit < 0)
+ goto theend;
+ }
+#endif
}
+#ifdef FEAT_RELTIME
+ /* Set the time limit, if there is one. */
+ profile_setlimit(time_limit, &tm);
+#endif
+
/*
* This function does not accept SP_REPEAT and SP_RETCOUNT flags.
* Check to make sure only those flags are set.
@@ -14057,7 +14073,7 @@ search_cmn(argvars, match_pos, flagsp)
pos = save_cursor = curwin->w_cursor;
subpatnum = searchit(curwin, curbuf, &pos, dir, pat, 1L,
- options, RE_SEARCH, (linenr_T)lnum_stop);
+ options, RE_SEARCH, (linenr_T)lnum_stop, &tm);
if (subpatnum != FAIL)
{
if (flags & SP_SUBPAT)
@@ -14147,6 +14163,7 @@ searchpair_cmn(argvars, match_pos)
char_u nbuf3[NUMBUFLEN];
int retval = 0; /* default: FAIL */
long lnum_stop = 0;
+ long time_limit = 0;
/* Get the three pattern arguments: start, middle, end. */
spat = get_tv_string_chk(&argvars[0]);
@@ -14182,13 +14199,21 @@ searchpair_cmn(argvars, match_pos)
lnum_stop = get_tv_number_chk(&argvars[5], NULL);
if (lnum_stop < 0)
goto theend;
+#ifdef FEAT_RELTIME
+ if (argvars[6].v_type != VAR_UNKNOWN)
+ {
+ time_limit = get_tv_number_chk(&argvars[6], NULL);
+ if (time_limit < 0)
+ goto theend;
+ }
+#endif
}
}
if (skip == NULL)
goto theend; /* type error */
retval = do_searchpair(spat, mpat, epat, dir, skip, flags,
- match_pos, lnum_stop);
+ match_pos, lnum_stop, time_limit);
theend:
p_ws = save_p_ws;
@@ -14240,7 +14265,8 @@ f_searchpairpos(argvars, rettv)
* Returns 0 or -1 for no match,
*/
long
-do_searchpair(spat, mpat, epat, dir, skip, flags, match_pos, lnum_stop)
+do_searchpair(spat, mpat, epat, dir, skip, flags, match_pos,
+ lnum_stop, time_limit)
char_u *spat; /* start pattern */
char_u *mpat; /* middle pattern */
char_u *epat; /* end pattern */
@@ -14249,6 +14275,7 @@ do_searchpair(spat, mpat, epat, dir, skip, flags, match_pos, lnum_stop)
int flags; /* SP_SETPCMARK and other SP_ values */
pos_T *match_pos;
linenr_T lnum_stop; /* stop at this line if not zero */
+ long time_limit; /* stop after this many msec */
{
char_u *save_cpo;
char_u *pat, *pat2 = NULL, *pat3 = NULL;
@@ -14263,11 +14290,17 @@ do_searchpair(spat, mpat, epat, dir, skip, flags, match_pos, lnum_stop)
int nest = 1;
int err;
int options = SEARCH_KEEP;
+ proftime_T tm;
/* Make 'cpoptions' empty, the 'l' flag should not be used here. */
save_cpo = p_cpo;
p_cpo = (char_u *)"";
+#ifdef FEAT_RELTIME
+ /* Set the time limit, if there is one. */
+ profile_setlimit(time_limit, &tm);
+#endif
+
/* Make two search patterns: start/end (pat2, for in nested pairs) and
* start/middle/end (pat3, for the top pair). */
pat2 = alloc((unsigned)(STRLEN(spat) + STRLEN(epat) + 15));
@@ -14291,7 +14324,7 @@ do_searchpair(spat, mpat, epat, dir, skip, flags, match_pos, lnum_stop)
for (;;)
{
n = searchit(curwin, curbuf, &pos, dir, pat, 1L,
- options, RE_SEARCH, lnum_stop);
+ options, RE_SEARCH, lnum_stop, &tm);
if (n == FAIL || (firstpos.lnum != 0 && equalpos(pos, firstpos)))
/* didn't find it or found the first match again: FAIL */
break;
diff --git a/src/ex_cmds2.c b/src/ex_cmds2.c
index dbbd8eca68..2eeb7527d3 100644
--- a/src/ex_cmds2.c
+++ b/src/ex_cmds2.c
@@ -895,19 +895,61 @@ profile_msg(tm)
sprintf(buf, "%10.6lf", (double)tm->QuadPart / (double)fr.QuadPart);
# else
sprintf(buf, "%3ld.%06ld", (long)tm->tv_sec, (long)tm->tv_usec);
-#endif
+# endif
return buf;
}
-# endif /* FEAT_PROFILE || FEAT_RELTIME */
+/*
+ * Put the time "msec" past now in "tm".
+ */
+ void
+profile_setlimit(msec, tm)
+ long msec;
+ proftime_T *tm;
+{
+ if (msec <= 0) /* no limit */
+ profile_zero(tm);
+ else
+ {
+# ifdef WIN3264
+ LARGE_INTEGER fr;
+
+ QueryPerformanceCounter(tm);
+ QueryPerformanceFrequency(&fr);
+ tm->QuadPart += (double)msec / 1000.0 * (double)fr.QuadPart;
+# else
+ long usec;
+
+ gettimeofday(tm, NULL);
+ usec = (long)tm->tv_usec + (long)msec * 1000;
+ tm->tv_usec = usec % 1000000L;
+ tm->tv_sec += usec / 1000000L;
+# endif
+ }
+}
-# if defined(FEAT_PROFILE) || defined(PROTO)
/*
- * Functions for profiling.
+ * Return TRUE if the current time is past "tm".
*/
-static void script_do_profile __ARGS((scriptitem_T *si));
-static void script_dump_profile __ARGS((FILE *fd));
-static proftime_T prof_wait_time;
+ int
+profile_passed_limit(tm)
+ proftime_T *tm;
+{
+ proftime_T now;
+
+# ifdef WIN3264
+ if (tm->QuadPart == 0) /* timer was not set */
+ return FALSE;
+ QueryPerformanceCounter(&now);
+ return (now.QuadPart > tm->QuadPart);
+# else
+ if (tm->tv_sec == 0) /* timer was not set */
+ return FALSE;
+ gettimeofday(&now, NULL);
+ return (now.tv_sec > tm->tv_sec
+ || (now.tv_sec == tm->tv_sec && now.tv_usec > tm->tv_usec));
+# endif
+}
/*
* Set the time in "tm" to zero.
@@ -924,6 +966,16 @@ profile_zero(tm)
# endif
}
+# endif /* FEAT_PROFILE || FEAT_RELTIME */
+
+# if defined(FEAT_PROFILE) || defined(PROTO)
+/*
+ * Functions for profiling.
+ */
+static void script_do_profile __ARGS((scriptitem_T *si));
+static void script_dump_profile __ARGS((FILE *fd));
+static proftime_T prof_wait_time;
+
/*
* Add the time "tm2" to "tm".
*/
diff --git a/src/ex_docmd.c b/src/ex_docmd.c
index 4c16b083f7..249ecb5e79 100644
--- a/src/ex_docmd.c
+++ b/src/ex_docmd.c
@@ -3979,7 +3979,7 @@ get_address(ptr, skip, to_other_file)
*cmd == '?' ? BACKWARD : FORWARD,
(char_u *)"", 1L,
SEARCH_MSG + SEARCH_START,
- i, (linenr_T)0) != FAIL)
+ i, (linenr_T)0, NULL) != FAIL)
lnum = pos.lnum;
else
{
diff --git a/src/normal.c b/src/normal.c
index f2c0089824..e310a37251 100644
--- a/src/normal.c
+++ b/src/normal.c
@@ -4194,7 +4194,7 @@ find_decl(ptr, len, locally, thisblock, searchflags)
for (;;)
{
t = searchit(curwin, curbuf, &curwin->w_cursor, FORWARD,
- pat, 1L, searchflags, RE_LAST, (linenr_T)0);
+ pat, 1L, searchflags, RE_LAST, (linenr_T)0, NULL);
if (curwin->w_cursor.lnum >= old_pos.lnum)
t = FAIL; /* match after start is failure too */
diff --git a/src/proto/eval.pro b/src/proto/eval.pro
index c6097c4299..def81e397f 100644
--- a/src/proto/eval.pro
+++ b/src/proto/eval.pro
@@ -54,7 +54,7 @@ char_u *get_dict_string __ARGS((dict_T *d, char_u *key, int save));
long get_dict_number __ARGS((dict_T *d, char_u *key));
char_u *get_function_name __ARGS((expand_T *xp, int idx));
char_u *get_expr_name __ARGS((expand_T *xp, int idx));
-long do_searchpair __ARGS((char_u *spat, char_u *mpat, char_u *epat, int dir, char_u *skip, int flags, pos_T *match_pos, linenr_T lnum_stop));
+long do_searchpair __ARGS((char_u *spat, char_u *mpat, char_u *epat, int dir, char_u *skip, int flags, pos_T *match_pos, linenr_T lnum_stop, long time_limit));
void set_vim_var_nr __ARGS((int idx, long val));
long get_vim_var_nr __ARGS((int idx));
char_u *get_vim_var_str __ARGS((int idx));
diff --git a/src/proto/ex_cmds2.pro b/src/proto/ex_cmds2.pro
index 11480f1ec0..88cfeb7a37 100644
--- a/src/proto/ex_cmds2.pro
+++ b/src/proto/ex_cmds2.pro
@@ -14,6 +14,8 @@ void profile_start __ARGS((proftime_T *tm));
void profile_end __ARGS((proftime_T *tm));
void profile_sub __ARGS((proftime_T *tm, proftime_T *tm2));
char *profile_msg __ARGS((proftime_T *tm));
+void profile_setlimit __ARGS((long msec, proftime_T *tm));
+int profile_passed_limit __ARGS((proftime_T *tm));
void profile_zero __ARGS((proftime_T *tm));
void profile_add __ARGS((proftime_T *tm, proftime_T *tm2));
void profile_self __ARGS((proftime_T *self, proftime_T *total, proftime_T *children));
diff --git a/src/proto/search.pro b/src/proto/search.pro
index b103f43329..f7c993fb47 100644
--- a/src/proto/search.pro
+++ b/src/proto/search.pro
@@ -10,7 +10,7 @@ char_u *last_search_pat __ARGS((void));
void reset_search_dir __ARGS((void));
void set_last_search_pat __ARGS((char_u *s, int idx, int magic, int setlast));
void last_pat_prog __ARGS((regmmatch_T *regmatch));
-int searchit __ARGS((win_T *win, buf_T *buf, pos_T *pos, int dir, char_u *pat, long count, int options, int pat_use, linenr_T stop_lnum));
+int searchit __ARGS((win_T *win, buf_T *buf, pos_T *pos, int dir, char_u *pat, long count, int options, int pat_use, linenr_T stop_lnum, proftime_T *tm));
int do_search __ARGS((oparg_T *oap, int dirc, char_u *pat, long count, int options));
int search_for_exact_line __ARGS((buf_T *buf, pos_T *pos, int dir, char_u *pat));
int searchc __ARGS((cmdarg_T *cap, int t_cmd));
diff --git a/src/search.c b/src/search.c
index 161117b584..035733b4a1 100644
--- a/src/search.c
+++ b/src/search.c
@@ -494,8 +494,9 @@ last_pat_prog(regmatch)
* When FEAT_EVAL is defined, returns the index of the first matching
* subpattern plus one; one if there was none.
*/
+/*ARGSUSED*/
int
-searchit(win, buf, pos, dir, pat, count, options, pat_use, stop_lnum)
+searchit(win, buf, pos, dir, pat, count, options, pat_use, stop_lnum, tm)
win_T *win; /* window to search in; can be NULL for a
buffer without a window! */
buf_T *buf;
@@ -506,6 +507,7 @@ searchit(win, buf, pos, dir, pat, count, options, pat_use, stop_lnum)
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; /* timeout limit or NULL */
{
int found;
linenr_T lnum; /* no init to shut up Apollo cc */
@@ -594,6 +596,11 @@ searchit(win, buf, pos, dir, pat, count, options, pat_use, stop_lnum)
if (stop_lnum != 0 && (dir == FORWARD
? lnum > stop_lnum : lnum < stop_lnum))
break;
+#ifdef FEAT_RELTIME
+ /* Stop after passing the "tm" time limit. */
+ if (tm != NULL && profile_passed_limit(tm))
+ break;
+#endif
/*
* Look for a match somewhere in line "lnum".
@@ -1249,7 +1256,7 @@ do_search(oap, dirc, pat, count, options)
(SEARCH_KEEP + SEARCH_PEEK + SEARCH_HIS
+ SEARCH_MSG + SEARCH_START
+ ((pat != NULL && *pat == ';') ? 0 : SEARCH_NOOF))),
- RE_LAST, (linenr_T)0);
+ RE_LAST, (linenr_T)0, NULL);
if (dircp != NULL)
*dircp = dirc; /* restore second '/' or '?' for normal_cmd() */
@@ -3780,7 +3787,7 @@ again:
if (do_searchpair((char_u *)"<[^ \t>/!]\\+\\%(\\_s\\_[^>]\\{-}[^/]>\\|$\\|\\_s\\=>\\)",
(char_u *)"",
(char_u *)"</[^>]*>", BACKWARD, (char_u *)"", 0,
- NULL, (linenr_T)0) <= 0)
+ NULL, (linenr_T)0, 0L) <= 0)
{
curwin->w_cursor = old_pos;
goto theend;
@@ -3814,7 +3821,7 @@ again:
sprintf((char *)epat, "</%.*s>\\c", len, p);
r = do_searchpair(spat, (char_u *)"", epat, FORWARD, (char_u *)"",
- 0, NULL, (linenr_T)0);
+ 0, NULL, (linenr_T)0, 0L);
vim_free(spat);
vim_free(epat);
diff --git a/src/version.c b/src/version.c
index b8182d6a0c..c41c2d2863 100644
--- a/src/version.c
+++ b/src/version.c
@@ -667,6 +667,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 211,
+/**/
210,
/**/
209,