Mercurial > vim
comparison src/eval.c @ 1496:29c09fa57168 v7.1.211
updated for version 7.1-211
author | vimboss |
---|---|
date | Sun, 06 Jan 2008 19:07:36 +0000 |
parents | 3c17132458a1 |
children | ea9f418ed072 |
comparison
equal
deleted
inserted
replaced
1495:04265ffbda1f | 1496:29c09fa57168 |
---|---|
7211 {"remove", 2, 3, f_remove}, | 7211 {"remove", 2, 3, f_remove}, |
7212 {"rename", 2, 2, f_rename}, | 7212 {"rename", 2, 2, f_rename}, |
7213 {"repeat", 2, 2, f_repeat}, | 7213 {"repeat", 2, 2, f_repeat}, |
7214 {"resolve", 1, 1, f_resolve}, | 7214 {"resolve", 1, 1, f_resolve}, |
7215 {"reverse", 1, 1, f_reverse}, | 7215 {"reverse", 1, 1, f_reverse}, |
7216 {"search", 1, 3, f_search}, | 7216 {"search", 1, 4, f_search}, |
7217 {"searchdecl", 1, 3, f_searchdecl}, | 7217 {"searchdecl", 1, 3, f_searchdecl}, |
7218 {"searchpair", 3, 6, f_searchpair}, | 7218 {"searchpair", 3, 7, f_searchpair}, |
7219 {"searchpairpos", 3, 6, f_searchpairpos}, | 7219 {"searchpairpos", 3, 7, f_searchpairpos}, |
7220 {"searchpos", 1, 3, f_searchpos}, | 7220 {"searchpos", 1, 4, f_searchpos}, |
7221 {"server2client", 2, 2, f_server2client}, | 7221 {"server2client", 2, 2, f_server2client}, |
7222 {"serverlist", 0, 0, f_serverlist}, | 7222 {"serverlist", 0, 0, f_serverlist}, |
7223 {"setbufvar", 3, 3, f_setbufvar}, | 7223 {"setbufvar", 3, 3, f_setbufvar}, |
7224 {"setcmdpos", 1, 1, f_setcmdpos}, | 7224 {"setcmdpos", 1, 1, f_setcmdpos}, |
7225 {"setline", 2, 2, f_setline}, | 7225 {"setline", 2, 2, f_setline}, |
14018 pos_T save_cursor; | 14018 pos_T save_cursor; |
14019 int save_p_ws = p_ws; | 14019 int save_p_ws = p_ws; |
14020 int dir; | 14020 int dir; |
14021 int retval = 0; /* default: FAIL */ | 14021 int retval = 0; /* default: FAIL */ |
14022 long lnum_stop = 0; | 14022 long lnum_stop = 0; |
14023 proftime_T tm; | |
14024 #ifdef FEAT_RELTIME | |
14025 long time_limit = 0; | |
14026 #endif | |
14023 int options = SEARCH_KEEP; | 14027 int options = SEARCH_KEEP; |
14024 int subpatnum; | 14028 int subpatnum; |
14025 | 14029 |
14026 pat = get_tv_string(&argvars[0]); | 14030 pat = get_tv_string(&argvars[0]); |
14027 dir = get_search_arg(&argvars[1], flagsp); /* may set p_ws */ | 14031 dir = get_search_arg(&argvars[1], flagsp); /* may set p_ws */ |
14031 if (flags & SP_START) | 14035 if (flags & SP_START) |
14032 options |= SEARCH_START; | 14036 options |= SEARCH_START; |
14033 if (flags & SP_END) | 14037 if (flags & SP_END) |
14034 options |= SEARCH_END; | 14038 options |= SEARCH_END; |
14035 | 14039 |
14036 /* Optional extra argument: line number to stop searching. */ | 14040 /* Optional arguments: line number to stop searching and timeout. */ |
14037 if (argvars[1].v_type != VAR_UNKNOWN | 14041 if (argvars[1].v_type != VAR_UNKNOWN && argvars[2].v_type != VAR_UNKNOWN) |
14038 && argvars[2].v_type != VAR_UNKNOWN) | |
14039 { | 14042 { |
14040 lnum_stop = get_tv_number_chk(&argvars[2], NULL); | 14043 lnum_stop = get_tv_number_chk(&argvars[2], NULL); |
14041 if (lnum_stop < 0) | 14044 if (lnum_stop < 0) |
14042 goto theend; | 14045 goto theend; |
14043 } | 14046 #ifdef FEAT_RELTIME |
14047 if (argvars[3].v_type != VAR_UNKNOWN) | |
14048 { | |
14049 time_limit = get_tv_number_chk(&argvars[3], NULL); | |
14050 if (time_limit < 0) | |
14051 goto theend; | |
14052 } | |
14053 #endif | |
14054 } | |
14055 | |
14056 #ifdef FEAT_RELTIME | |
14057 /* Set the time limit, if there is one. */ | |
14058 profile_setlimit(time_limit, &tm); | |
14059 #endif | |
14044 | 14060 |
14045 /* | 14061 /* |
14046 * This function does not accept SP_REPEAT and SP_RETCOUNT flags. | 14062 * This function does not accept SP_REPEAT and SP_RETCOUNT flags. |
14047 * Check to make sure only those flags are set. | 14063 * Check to make sure only those flags are set. |
14048 * Also, Only the SP_NOMOVE or the SP_SETPCMARK flag can be set. Both | 14064 * Also, Only the SP_NOMOVE or the SP_SETPCMARK flag can be set. Both |
14055 goto theend; | 14071 goto theend; |
14056 } | 14072 } |
14057 | 14073 |
14058 pos = save_cursor = curwin->w_cursor; | 14074 pos = save_cursor = curwin->w_cursor; |
14059 subpatnum = searchit(curwin, curbuf, &pos, dir, pat, 1L, | 14075 subpatnum = searchit(curwin, curbuf, &pos, dir, pat, 1L, |
14060 options, RE_SEARCH, (linenr_T)lnum_stop); | 14076 options, RE_SEARCH, (linenr_T)lnum_stop, &tm); |
14061 if (subpatnum != FAIL) | 14077 if (subpatnum != FAIL) |
14062 { | 14078 { |
14063 if (flags & SP_SUBPAT) | 14079 if (flags & SP_SUBPAT) |
14064 retval = subpatnum; | 14080 retval = subpatnum; |
14065 else | 14081 else |
14145 char_u nbuf1[NUMBUFLEN]; | 14161 char_u nbuf1[NUMBUFLEN]; |
14146 char_u nbuf2[NUMBUFLEN]; | 14162 char_u nbuf2[NUMBUFLEN]; |
14147 char_u nbuf3[NUMBUFLEN]; | 14163 char_u nbuf3[NUMBUFLEN]; |
14148 int retval = 0; /* default: FAIL */ | 14164 int retval = 0; /* default: FAIL */ |
14149 long lnum_stop = 0; | 14165 long lnum_stop = 0; |
14166 long time_limit = 0; | |
14150 | 14167 |
14151 /* Get the three pattern arguments: start, middle, end. */ | 14168 /* Get the three pattern arguments: start, middle, end. */ |
14152 spat = get_tv_string_chk(&argvars[0]); | 14169 spat = get_tv_string_chk(&argvars[0]); |
14153 mpat = get_tv_string_buf_chk(&argvars[1], nbuf1); | 14170 mpat = get_tv_string_buf_chk(&argvars[1], nbuf1); |
14154 epat = get_tv_string_buf_chk(&argvars[2], nbuf2); | 14171 epat = get_tv_string_buf_chk(&argvars[2], nbuf2); |
14180 if (argvars[5].v_type != VAR_UNKNOWN) | 14197 if (argvars[5].v_type != VAR_UNKNOWN) |
14181 { | 14198 { |
14182 lnum_stop = get_tv_number_chk(&argvars[5], NULL); | 14199 lnum_stop = get_tv_number_chk(&argvars[5], NULL); |
14183 if (lnum_stop < 0) | 14200 if (lnum_stop < 0) |
14184 goto theend; | 14201 goto theend; |
14202 #ifdef FEAT_RELTIME | |
14203 if (argvars[6].v_type != VAR_UNKNOWN) | |
14204 { | |
14205 time_limit = get_tv_number_chk(&argvars[6], NULL); | |
14206 if (time_limit < 0) | |
14207 goto theend; | |
14208 } | |
14209 #endif | |
14185 } | 14210 } |
14186 } | 14211 } |
14187 if (skip == NULL) | 14212 if (skip == NULL) |
14188 goto theend; /* type error */ | 14213 goto theend; /* type error */ |
14189 | 14214 |
14190 retval = do_searchpair(spat, mpat, epat, dir, skip, flags, | 14215 retval = do_searchpair(spat, mpat, epat, dir, skip, flags, |
14191 match_pos, lnum_stop); | 14216 match_pos, lnum_stop, time_limit); |
14192 | 14217 |
14193 theend: | 14218 theend: |
14194 p_ws = save_p_ws; | 14219 p_ws = save_p_ws; |
14195 | 14220 |
14196 return retval; | 14221 return retval; |
14238 * Search for a start/middle/end thing. | 14263 * Search for a start/middle/end thing. |
14239 * Used by searchpair(), see its documentation for the details. | 14264 * Used by searchpair(), see its documentation for the details. |
14240 * Returns 0 or -1 for no match, | 14265 * Returns 0 or -1 for no match, |
14241 */ | 14266 */ |
14242 long | 14267 long |
14243 do_searchpair(spat, mpat, epat, dir, skip, flags, match_pos, lnum_stop) | 14268 do_searchpair(spat, mpat, epat, dir, skip, flags, match_pos, |
14269 lnum_stop, time_limit) | |
14244 char_u *spat; /* start pattern */ | 14270 char_u *spat; /* start pattern */ |
14245 char_u *mpat; /* middle pattern */ | 14271 char_u *mpat; /* middle pattern */ |
14246 char_u *epat; /* end pattern */ | 14272 char_u *epat; /* end pattern */ |
14247 int dir; /* BACKWARD or FORWARD */ | 14273 int dir; /* BACKWARD or FORWARD */ |
14248 char_u *skip; /* skip expression */ | 14274 char_u *skip; /* skip expression */ |
14249 int flags; /* SP_SETPCMARK and other SP_ values */ | 14275 int flags; /* SP_SETPCMARK and other SP_ values */ |
14250 pos_T *match_pos; | 14276 pos_T *match_pos; |
14251 linenr_T lnum_stop; /* stop at this line if not zero */ | 14277 linenr_T lnum_stop; /* stop at this line if not zero */ |
14278 long time_limit; /* stop after this many msec */ | |
14252 { | 14279 { |
14253 char_u *save_cpo; | 14280 char_u *save_cpo; |
14254 char_u *pat, *pat2 = NULL, *pat3 = NULL; | 14281 char_u *pat, *pat2 = NULL, *pat3 = NULL; |
14255 long retval = 0; | 14282 long retval = 0; |
14256 pos_T pos; | 14283 pos_T pos; |
14261 int n; | 14288 int n; |
14262 int r; | 14289 int r; |
14263 int nest = 1; | 14290 int nest = 1; |
14264 int err; | 14291 int err; |
14265 int options = SEARCH_KEEP; | 14292 int options = SEARCH_KEEP; |
14293 proftime_T tm; | |
14266 | 14294 |
14267 /* Make 'cpoptions' empty, the 'l' flag should not be used here. */ | 14295 /* Make 'cpoptions' empty, the 'l' flag should not be used here. */ |
14268 save_cpo = p_cpo; | 14296 save_cpo = p_cpo; |
14269 p_cpo = (char_u *)""; | 14297 p_cpo = (char_u *)""; |
14298 | |
14299 #ifdef FEAT_RELTIME | |
14300 /* Set the time limit, if there is one. */ | |
14301 profile_setlimit(time_limit, &tm); | |
14302 #endif | |
14270 | 14303 |
14271 /* Make two search patterns: start/end (pat2, for in nested pairs) and | 14304 /* Make two search patterns: start/end (pat2, for in nested pairs) and |
14272 * start/middle/end (pat3, for the top pair). */ | 14305 * start/middle/end (pat3, for the top pair). */ |
14273 pat2 = alloc((unsigned)(STRLEN(spat) + STRLEN(epat) + 15)); | 14306 pat2 = alloc((unsigned)(STRLEN(spat) + STRLEN(epat) + 15)); |
14274 pat3 = alloc((unsigned)(STRLEN(spat) + STRLEN(mpat) + STRLEN(epat) + 23)); | 14307 pat3 = alloc((unsigned)(STRLEN(spat) + STRLEN(mpat) + STRLEN(epat) + 23)); |
14289 clearpos(&foundpos); | 14322 clearpos(&foundpos); |
14290 pat = pat3; | 14323 pat = pat3; |
14291 for (;;) | 14324 for (;;) |
14292 { | 14325 { |
14293 n = searchit(curwin, curbuf, &pos, dir, pat, 1L, | 14326 n = searchit(curwin, curbuf, &pos, dir, pat, 1L, |
14294 options, RE_SEARCH, lnum_stop); | 14327 options, RE_SEARCH, lnum_stop, &tm); |
14295 if (n == FAIL || (firstpos.lnum != 0 && equalpos(pos, firstpos))) | 14328 if (n == FAIL || (firstpos.lnum != 0 && equalpos(pos, firstpos))) |
14296 /* didn't find it or found the first match again: FAIL */ | 14329 /* didn't find it or found the first match again: FAIL */ |
14297 break; | 14330 break; |
14298 | 14331 |
14299 if (firstpos.lnum == 0) | 14332 if (firstpos.lnum == 0) |