comparison src/quickfix.c @ 153:19670b05ee32

updated for version 7.0047
author vimboss
date Wed, 02 Feb 2005 23:04:36 +0000
parents 2983cde45542
children 6df0106fc595
comparison
equal deleted inserted replaced
152:c837baf03d43 153:19670b05ee32
2254 ex_vimgrep(eap) 2254 ex_vimgrep(eap)
2255 exarg_T *eap; 2255 exarg_T *eap;
2256 { 2256 {
2257 regmmatch_T regmatch; 2257 regmmatch_T regmatch;
2258 char_u *save_cpo; 2258 char_u *save_cpo;
2259 int fcount; 2259 int fcount;
2260 char_u **fnames; 2260 char_u **fnames;
2261 char_u *s; 2261 char_u *s;
2262 char_u *p; 2262 char_u *p;
2263 int i; 2263 int i;
2264 int fi; 2264 int fi;
2265 struct qf_line *prevp = NULL; 2265 struct qf_line *prevp = NULL;
2266 long lnum; 2266 long lnum;
2267 garray_T ga; 2267 garray_T ga;
2268 buf_T *buf; 2268 buf_T *buf;
2269 int duplicate_name = FALSE; 2269 int duplicate_name = FALSE;
2280 save_cpo = p_cpo; 2280 save_cpo = p_cpo;
2281 p_cpo = empty_option; 2281 p_cpo = empty_option;
2282 2282
2283 /* Get the search pattern: either white-separated or enclosed in // */ 2283 /* Get the search pattern: either white-separated or enclosed in // */
2284 regmatch.regprog = NULL; 2284 regmatch.regprog = NULL;
2285 if (vim_isIDc(*eap->arg)) 2285 p = skip_vimgrep_pat(eap->arg, &s);
2286 { 2286 if (p == NULL)
2287 s = eap->arg; 2287 {
2288 p = skiptowhite(s); 2288 EMSG(_("E682: Invalid search pattern or delimiter"));
2289 } 2289 goto theend;
2290 else
2291 {
2292 s = eap->arg + 1;
2293 p = skip_regexp(s, *eap->arg, TRUE, NULL);
2294 if (*p != *eap->arg)
2295 {
2296 EMSG(_("E682: Invalid search pattern or delimiter"));
2297 goto theend;
2298 }
2299 } 2290 }
2300 if (*p != NUL) 2291 if (*p != NUL)
2301 *p++ = NUL; 2292 *p++ = NUL;
2302 regmatch.regprog = vim_regcomp(s, RE_MAGIC); 2293 regmatch.regprog = vim_regcomp(s, RE_MAGIC);
2303 if (regmatch.regprog == NULL) 2294 if (regmatch.regprog == NULL)
2389 smsg((char_u *)_("Cannot open file \"%s\""), fnames[fi]); 2380 smsg((char_u *)_("Cannot open file \"%s\""), fnames[fi]);
2390 } 2381 }
2391 else 2382 else
2392 { 2383 {
2393 found_match = FALSE; 2384 found_match = FALSE;
2385 #ifdef HAVE_SETJMP_H
2386 /*
2387 * Matching with a regexp may cause a very deep recursive call of
2388 * regmatch(). Vim will crash when running out of stack space.
2389 * Catch this here if the system supports it.
2390 * It's a bit slow, thus do it outside of the loop.
2391 */
2392 mch_startjmp();
2393 if (SETJMP(lc_jump_env) != 0)
2394 {
2395 mch_didjmp();
2396 # ifdef SIGHASARG
2397 if (lc_signal != SIGINT)
2398 # endif
2399 EMSG(_(e_complex));
2400 got_int = TRUE;
2401 goto jumpend;
2402 }
2403 #endif
2394 for (lnum = 1; lnum <= buf->b_ml.ml_line_count; ++lnum) 2404 for (lnum = 1; lnum <= buf->b_ml.ml_line_count; ++lnum)
2395 { 2405 {
2396 if (vim_regexec_multi(&regmatch, curwin, buf, lnum, 2406 if (vim_regexec_multi(&regmatch, curwin, buf, lnum,
2397 (colnr_T)0) > 0) 2407 (colnr_T)0) > 0)
2398 { 2408 {
2417 } 2427 }
2418 line_breakcheck(); 2428 line_breakcheck();
2419 if (got_int) 2429 if (got_int)
2420 break; 2430 break;
2421 } 2431 }
2432 #ifdef HAVE_SETJMP_H
2433 jumpend:
2434 mch_endjmp();
2435 #endif
2422 2436
2423 if (using_dummy) 2437 if (using_dummy)
2424 { 2438 {
2425 if (found_match && first_match_buf == NULL) 2439 if (found_match && first_match_buf == NULL)
2426 first_match_buf = buf; 2440 first_match_buf = buf;
2451 2465
2452 #if defined(FEAT_AUTOCMD) && defined(FEAT_SYN_HL) 2466 #if defined(FEAT_AUTOCMD) && defined(FEAT_SYN_HL)
2453 if (buf != NULL) 2467 if (buf != NULL)
2454 { 2468 {
2455 /* The buffer is still loaded, the Filetype autocommands 2469 /* The buffer is still loaded, the Filetype autocommands
2456 * need to be done now, in that buffer. */ 2470 * need to be done now, in that buffer. And then the
2471 * modelines (again). */
2457 aucmd_prepbuf(&aco, buf); 2472 aucmd_prepbuf(&aco, buf);
2458 apply_autocmds(EVENT_FILETYPE, buf->b_p_ft, 2473 apply_autocmds(EVENT_FILETYPE, buf->b_p_ft,
2459 buf->b_fname, TRUE, buf); 2474 buf->b_fname, TRUE, buf);
2475 do_modelines(FALSE);
2460 aucmd_restbuf(&aco); 2476 aucmd_restbuf(&aco);
2461 } 2477 }
2462 #endif 2478 #endif
2463 } 2479 }
2464 } 2480 }
2486 /* Only resture 'cpo' when it wasn't set in the mean time. */ 2502 /* Only resture 'cpo' when it wasn't set in the mean time. */
2487 if (p_cpo == empty_option) 2503 if (p_cpo == empty_option)
2488 p_cpo = save_cpo; 2504 p_cpo = save_cpo;
2489 else 2505 else
2490 free_string_option(save_cpo); 2506 free_string_option(save_cpo);
2507 }
2508
2509 /*
2510 * Skip over the pattern argument of ":vimgrep /pat/".
2511 * Put the start of the pattern in "*s", unless "s" is NULL.
2512 * Return a pointer to the char just past the pattern.
2513 */
2514 char_u *
2515 skip_vimgrep_pat(p, s)
2516 char_u *p;
2517 char_u **s;
2518 {
2519 int c;
2520
2521 if (vim_isIDc(*p))
2522 {
2523 if (s != NULL)
2524 *s = p;
2525 return skiptowhite(p);
2526 }
2527 if (s != NULL)
2528 *s = p + 1;
2529 c = *p;
2530 p = skip_regexp(p + 1, c, TRUE, NULL);
2531 if (*p != c)
2532 return NULL;
2533 return p;
2491 } 2534 }
2492 2535
2493 /* 2536 /*
2494 * Load file "fname" into a dummy buffer and return the buffer pointer. 2537 * Load file "fname" into a dummy buffer and return the buffer pointer.
2495 * Returns NULL if it fails. 2538 * Returns NULL if it fails.